﻿using System;
using System.Diagnostics.Contracts;

namespace OpenLS.Spreadsheet.Formats.Biff.Records
{
    internal class FeatHdr11Record : BiffRecord
    {
        private FrtHeader frtHeader = new FrtHeader(){_rt = 0x0871};
        private SharedFeatureType isf;
        private uint reserved2 = 0xFFFFFFFF;
        private uint reserved3 = 0xFFFFFFFF;
        private uint idListNext;
        private ushort reserved4;
        private byte reserved1 = 1;

        public FeatHdr11Record(int next)
        {
            this.isf = SharedFeatureType.ISFLIST;
            this.idListNext = (uint) next;
            idListNext = 4; //\\
        }

        public FeatHdr11Record()
        {
        }

        protected override void ReadContent(BiffReaderContext context, int length)
        {
            frtHeader = new FrtHeader();
            frtHeader.Read(context.Reader);
            Contract.Assert(frtHeader._rt == 0x0871);
            this.isf = (SharedFeatureType) context.ReadUInt16();
            this.reserved1 = context.ReadByte();
            this.reserved2 = context.ReadUInt32();
            this.reserved3 = context.ReadUInt32();
            this.idListNext = context.ReadUInt32();
            this.reserved4 = context.ReadUInt16();
        }

        internal override BiffRecordType RecordType
        {
            get { return BiffRecordType.FeatHdr11; }
        }

        internal override void WriteContent(BiffWriterWorkbookContext context)
        {
            Contract.Assert(frtHeader._rt == 0x0871);
            frtHeader.Write(context);
            context.Write((ushort)this.isf);
            context.Write(reserved1);
            context.Write(this.reserved2 );
            context.Write(this.reserved3);
            context.Write(this.idListNext );
            context.Write(this.reserved4);
        }
    }
}